<style lang="less">
    @import './own-space.less';
</style>

<template>
    <div>
        <Card>
            <p slot="title">
                <Icon type="person"></Icon>
                个人信息
            </p>
            <div>
                <i-Form 
                    :model="userForm" 
                    :label-width="100" 
                    label-position="right"
                >
                    <FormItem label="用户姓名：">
                        <div style="display:inline-block;width:300px;">
                            <i-Input v-model="userForm.username" ></i-Input>
                        </div>
                    </FormItem>
                    <FormItem label="密码：">
                        <div style="display:inline-block;width:300px;">
                            <i-Input :type="passtype" v-model="userForm.password" ></i-Input>
                        </div>
                    </FormItem>
                    <FormItem label="个人昵称：">
                        <div style="display:inline-block;width:300px;">
                            <i-Input v-model="userForm.penname" ></i-Input>
                        </div>
                    </FormItem>
                    <FormItem label="登录到期时间：">
                        <span>{{ userForm.endtime }}</span>
                    </FormItem>
                    <FormItem label="登录次数：">
                        <span>{{ userForm.hits }}</span>
                    </FormItem>
                    <div>
                        <Button type="text" style="width: 100px;" @click="cancelEditUserInfor">取消</Button>
                        <Button type="primary" style="width: 100px;" :loading="save_loading" @click="saveEdit">保存</Button>
                    </div>
                </i-Form>
            </div>
        </Card>
    </div>
</template>

<script>
import Cookies from 'js-cookie';
import api from '../../libs/api';
export default {
    name: 'ownspace_index',
    data () {
        return {
            passtype:'text',
            userForm: {},      
            save_loading:false      
        };
    },
    methods: {
        
        cancelEditUserInfor () {
            this.$store.commit('removeTag', 'ownspace_index');
            localStorage.pageOpenedList = JSON.stringify(this.$store.state.app.pageOpenedList);
            let lastPageName = '';
            if (this.$store.state.app.pageOpenedList.length > 1) {
                lastPageName = this.$store.state.app.pageOpenedList[1].name;
            } else {
                lastPageName = this.$store.state.app.pageOpenedList[0].name;
            }
            this.$router.push({
                name: lastPageName
            });
        },
        saveEdit () {
            this.saveInfoAjax();
        },
        init () {
            var vm=this;
            var userinfo= wlfData.userinfo;
            api.get("user/get/"+userinfo.ID).then(function(res){
                vm.userForm=res.data.msg;
                
            setTimeout(function(){vm.passtype="password"},1000);
            });
        },
        saveInfoAjax () {
            this.save_loading = true;
            var vm=this;
            api.post("user/save",this.userForm).then(function(res){
                vm.$Message.success('保存成功');
                vm.save_loading = false;
            })
        }
    },
    mounted () {
        this.init();
    }
};
</script>
